package monitorDaoImpl

import (
	"baize/app/business/monitor/monitorModels"
	"baize/app/datasource"
	"context"
	"go.mongodb.org/mongo-driver/mongo"
)

type LogininforMapper struct {
	collection func(ctx context.Context) *mongo.Collection
}

func NewLogininforMapper(c *mongo.Client) *LogininforMapper {
	return &LogininforMapper{
		collection: func(ctx context.Context) *mongo.Collection {
			return c.Database(datasource.SysDatabase).Collection(datasource.Collection["loginInfo"])
		},
	}
}

func (ld *LogininforMapper) InserLogininfor(ctx context.Context, logininfor *monitorModels.Logininfor) {
	_, err := ld.collection(ctx).InsertOne(ctx, logininfor)
	if err != nil {
		panic(err)
	}
	return
}
func (ld *LogininforMapper) SelectLogininforList(ctx context.Context, logininfor *monitorModels.LogininforDQL) (list []*monitorModels.Logininfor, total *int64) {
	//whereSql := ``
	//if logininfor.IpAddr != "" {
	//	whereSql += " AND ipaddr like concat(:ipaddr, '%')"
	//}
	//if logininfor.Status != "" {
	//	whereSql += " AND  status = :status"
	//}
	//if logininfor.UserName != "" {
	//	whereSql += " AND user_name like concat('%', :user_name, '%')"
	//}
	//
	//if whereSql != "" {
	//	whereSql = " where " + whereSql[4:]
	//}
	//list = make([]*monitorModels.Logininfor, 0)
	//total = new(int64)
	//err := db.NamedSelectPageContext(ctx, &list, total, ld.selectSql+whereSql, logininfor, logininfor.ToPage())
	//if err != nil {
	//	panic(err)
	//}
	return
}
func (ld *LogininforMapper) SelectLogininforListAll(ctx context.Context, logininfor *monitorModels.LogininforDQL) (list []*monitorModels.Logininfor) {
	//whereSql := ``
	//if logininfor.IpAddr != "" {
	//	whereSql += " AND ipaddr like concat('%', :ipaddr, '%')"
	//}
	//if logininfor.Status != "" {
	//	whereSql += " AND  status = :status"
	//}
	//if logininfor.UserName != "" {
	//	whereSql += " AND user_name like concat('%', :userName, '%')"
	//}
	//
	//if whereSql != "" {
	//	whereSql = " where " + whereSql[4:]
	//}
	//list = make([]*monitorModels.Logininfor, 0)
	//err := db.NamedSelectContext(ctx, &list, ld.selectSql+whereSql, logininfor)
	//if err != nil {
	//	panic(err)
	//}
	return
}
func (ld *LogininforMapper) DeleteLogininforByIds(ctx context.Context, infoIds []int64) {
	//query, i, err := sqly.In("delete from sys_logininfor where info_id in (?)", infoIds)
	//if err != nil {
	//	panic(err)
	//}
	//_, err = db.ExecContext(ctx, query, i...)
	//if err != nil {
	//	panic(err)
	//}
}

func (ld *LogininforMapper) CleanLogininfor(ctx context.Context) {
	//_, err := db.ExecContext(ctx, "truncate table sys_logininfor")
	//if err != nil {
	//	panic(err)
	//}
}
